<?php

namespace App\Http\Controllers\PC\User;

use Illuminate\Http\Request;
use Session,Config;
use App\Http\Requests;
use App\Http\Service\User\UserService;
use App\Http\Controllers\Controller;

class LoginController extends Controller
{
    protected $login = 'PC.User.login';

    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * 用户登录视图
     */
    public function login()
    {
        $url = "";
        if(isset($_SERVER['HTTP_REFERER'])){
            $check_url =  $_SERVER['HTTP_REFERER'];

            if(strpos($check_url,'buy') || strpos($check_url,'user') && strpos($check_url,'niumoip.com') )
            {
                $url = $check_url;
            }
        }
        $title='登录';
        return view($this->login)->with('title',$title)->with("url",$url);
    }


    public function doLogin(Request $request)
    {
        $where = [];

        $data['name'] = $request->input('username');
        $data['password'] = $request->input('password');
        $data['flag'] = 'pc';

        $user = new UserService();
        $ret =  $user->login($data);

        $result = '';
        if($ret['code'] == 0)
        {
            $result = $ret['data'];
            Session::put(Config::get('custom.setting.MEMBER_TOKEN'),$result['token']);
            Session::put(Config::get('custom.setting.MEMBER_VIP_FLAG'),$result['vip_flag']);
            Session::put(Config::get('custom.setting.MEMBER_INFO'),$result['user']);
            unset($ret['data']);
        }
        return $ret;

    }



}
